<template>
  <div class="feedBack">
    <div class="feedBack-box">
      <h4>反馈类型</h4>
      <button size="mini" plain="true" :type="feedBack.feedBackType == item.dictValue ? 'primary':'default'"
              @click="handleClick(item)"
              v-for="(item,index) in typeList" :key="index"
              style="margin-left: 10rpx;margin-top: 10rpx"
      >
        {{item.dictLabel}}</button>
    </div>

    <div class="feedBack-box">
      <h4>问题反馈 <span style="margin-left:10rpx;" v-if="feedBack.feedBackType">@{{ typeList.find(item=>{return item.dictValue == feedBack.feedBackType }).dictLabel  }}</span></h4>
      <u-input class="field-input" height="400" :border-bottom="false" v-model="feedBack.content" type="textarea" placeholder="请输入反馈信息">
      </u-input>

      <view class="opt-view">
        <view class="img-title">上传凭证（最多2张）</view>
        <view class="images-view">
          <u-upload  :action="$utils.getUploadUrl()" width="150" @on-uploaded="onUploaded" :max-count="2" :show-progress="false"></u-upload>
        </view>
      </view>
    </div>

    <div class="feedBack-box">
      <h4>手机号</h4>
      <u-input :border-bottom="false" v-model="feedBack.contactNumber" placeholder="请输入您的手机号">
      </u-input>
    </div>

    <div class="submit" @click="submit()">提交</div>
  </div>

</template>

<script>
export default {
  data() {
    return {
      feedBack: {
        feedBackType: "0", //默认反馈问题为 '功能相关'
      },
      typeList: [],
    };
  },
  onShow() {
    this.loadFeedBackType()
  },
  methods: {
    loadFeedBackType(){
      this.$clApi.open.getDictData("feedback_type").then(res =>{
        this.typeList = res.data
      })
    },
    // 点击反馈内容
    handleClick(item) {
      this.$set(this.feedBack, "feedBackType", item.dictValue);
    },

    //图片上传
    onUploaded(lists) {
      let images = [];
      lists.forEach((item) => {
        images.push(item.response.data.url);
      });
      this.feedBack.imgs = images.join(",");
    },

    /**
     * 提交意见反馈
     */
    submit() {
      if (!this.feedBack.feedBackType) {
        uni.showToast({
          title: "请填写反馈类型",
          duration: 2000,
          icon: "none",
        });
        return false;
      }
      if (!this.feedBack.content) {
        uni.showToast({
          title: "请填写反馈信息",
          duration: 2000,
          icon: "none",
        });
        return false;
      }
      if (this.feedBack.contactNumber && !this.$u.test.mobile(this.feedBack.contactNumber)) {
        uni.showToast({
          title: "请填写您的正确手机号",
          duration: 2000,
          icon: "none",
        });
        return false;
      }
      /** 提交 */
      this.$clApi.member.fetchFeedBack(this.feedBack).then((res) => {
        uni.showToast({
          title: "提交成功!",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateBack({
            delta: 1,
          });
        }, 500);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.submit {
  text-align: center;
  background: $light-color;
  height: 70rpx;
  line-height: 70rpx;
  color: #fff;
  width: 92%;
  margin-bottom: 100rpx;
  margin: 0 auto;
  border-radius: 100px;
}
.active{
  color: $light-color !important;
  font-weight: bold;
}
.feedBack {
  padding-bottom: 100rpx;
}
.feedBack-box {
  background: #fff;
  border-radius: 20rpx;
  padding: 32rpx;
  margin-bottom: 40rpx;
}
/deep/ .u-input__textarea {
  padding: 12px;
}
.feedBack-box:nth-of-type(1) {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.feedBack-item {
  margin: 20rpx 0;
  font-size: 24rpx;
  color: #666;
}
h4 {
  font-size: 30rpx;
}
.field-input {
  margin: 20rpx 0;
  padding: 20rpx 0;
  background: #fafafa;
  border-radius: 0.6em;
}
</style>
